import Request from '@/utils/request'

const baseUrl = process.env.VUE_APP_BASE_BOSS_API_URL

export const bossRequest = new Request(baseUrl)

export const getMenuPage = (data: any) => {
  return bossRequest.request({
    method: 'post',
    url: '/menu/getMenuPages',
    data
  })
}

export const getAllMenus = () => {
  return bossRequest.request({
    method: 'get',
    url: '/menu/getAll'
  })
}

export const saveOrUpdateMenu = (data: any) => {
  return bossRequest.request({
    method: 'post',
    url: '/menu/saveOrUpdate',
    data
  })
}

export const delMenu = (id: number) => {
  return bossRequest.request({
    method: 'delete',
    url: `/menu/${id}`
  })
}

export const getMenuDetail = (id: number) => {
  return bossRequest.request({
    method: 'get',
    url: `/menu/${id}`
  })
}

export const getResourcePage = (data: any) => {
  return bossRequest.request({
    method: 'post',
    url: '/resource/getResourcePages',
    data
  })
}

export const getRolePages = (data: any) => {
  return bossRequest.request({
    method: 'post',
    url: '/role/getRolePages',
    data
  })
}

export const saveOrUpdate = (data: any) => {
  return bossRequest.request({
    method: 'post',
    url: '/role/saveOrUpdate',
    data
  })
}

export const delRole = (id: number) => {
  return bossRequest.request({
    method: 'delete',
    url: `/role/${id}`
  })
}

export const getMenuNodeList = () => {
  return bossRequest.request({
    method: 'get',
    url: '/menu/getMenuNodeList'
  })
}

export const getRoleMenus = (params: any) => {
  return bossRequest.request({
    method: 'get',
    url: '/menu/getRoleMenus',
    params
  })
}

export const allocateRoleMenus = (data: any) => {
  return bossRequest.request({
    method: 'post',
    url: '/menu/allocateRoleMenus',
    data
  })
}

export const getResourceCategory = () => {
  return bossRequest.request({
    method: 'get',
    url: '/resource/category/getAll'
  })
}

export const getResourceAll = () => {
  return bossRequest.request({
    method: 'get',
    url: '/resource/getAll'
  })
}

export const getRoleResources = (params: any) => {
  return bossRequest.request({
    method: 'get',
    url: '/resource/getRoleResources',
    params
  })
}

export const saveOrUpdateResource = (data: any) => {
  return bossRequest.request({
    method: 'post',
    url: '/resource/allocateRoleResources',
    data
  })
}

export const getUserPages = (data: any) => {
  return bossRequest.request({
    method: 'post',
    url: '/user/getUserPages',
    data
  })
}

export const forbidUser = (data: any) => {
  return bossRequest.request({
    method: 'post',
    url: '/user/forbidUser',
    data
  })
}

export const enableUser = (data: any) => {
  return bossRequest.request({
    method: 'post',
    url: '/user/enableUser',
    data
  })
}

export const getUserRole = (userId: number) => {
  return bossRequest.request({
    method: 'get',
    url: `/role/user/${userId}`
  })
}

export const getAllRoles = () => {
  return bossRequest.request({
    method: 'get',
    url: '/role/all'
  })
}

export const setUserRole = (data: any) => {
  return bossRequest.request({
    method: 'post',
    url: '/role/allocateUserRoles',
    data
  })
}
